package com.haliyoo.adhere.handler;

import java.util.ArrayList;

import com.haliyoo.adhere.R;
import com.haliyoo.adhere.activity.CreativeDesignActivity;
import com.haliyoo.adhere.activity.HallActivity;
import com.haliyoo.adhere.activity.HelpActivity;
import com.haliyoo.adhere.activity.LoginActivity;
import com.haliyoo.adhere.activity.OfficialWeiboActivity;
import com.haliyoo.adhere.widget.DialogListener;
import com.haliyoo.adhere.widget.PromptDialog;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MoreHandler {
	static Context context = null;
	
	public MoreHandler(Context context) {
		if (HallActivity.getCheckedId() != R.id.radio_more) {
			return;
		}
		
		this.context = context;

        LayoutInflater inflater = LayoutInflater.from(context);
        
		// / 设置标题栏
		RelativeLayout rlTitle = (RelativeLayout) ((Activity) context)
				.findViewById(R.id.main_title);

		View vTitle = inflater.inflate(R.layout.title_back_write, null);
		rlTitle.removeAllViews();
		rlTitle.addView(vTitle);

		// / 设置内容区
		LinearLayout llContent = (LinearLayout) ((Activity) context)
				.findViewById(R.id.llContent);
		View vContent = inflater.inflate(R.layout.more_list, null);
		llContent.removeAllViews();
		llContent.addView(vContent);

        TextView tvTitle = (TextView) ((Activity) context).findViewById(R.id.TEXT_VIEW_TITLE);
        tvTitle.setText(context.getString(R.string.more));

//        class MyMenu {
//        	public int layoutId = 0;
//        	public int iconId = 0;
//        	public int strId = 0;
//        	
//        	public MyMenu(int layoutId, int iconId, int strId) {
//        		this.layoutId = layoutId;
//        		this.iconId = iconId;
//        		this.strId = strId;
//        	}
//        }
//
//        ArrayList<MyMenu> myMenu = new ArrayList<MyMenu>();
//        myMenu.add(new MyMenu(R.id.llSetting, R.drawable.setting, R.string.menu_settings));
//        myMenu.add(new MyMenu(R.id.llOfficialWeibo, R.drawable.officialweibo, R.string.weibo_officialweibo));
//        myMenu.add(new MyMenu(R.id.llFeedback, R.drawable.feedback, R.string.weibo_feedback));
//        myMenu.add(new MyMenu(R.id.llAboutAdhere, R.drawable.aboutweibo, R.string.weibo_about));
//        myMenu.add(new MyMenu(R.id.llMenuExit, R.drawable.menu_exit, R.string.exit));
//        
//        for (MyMenu menu : myMenu) {
//        	LinearLayout llItem = (LinearLayout) ((Activity) context).findViewById(menu.layoutId);
//    		View vSubContent = inflater.inflate(R.layout.more_list_item, null);
//        	
//        	llItem.addView(vSubContent);
//        	
//        	ImageView ivIcon = (ImageView) ((Activity) context).findViewById(R.id.ivIcon);
//        	ivIcon.setBackgroundResource(menu.iconId);
//        	
//        	TextView tvText = (TextView) ((Activity) context).findViewById(R.id.ivText);
//        	tvText.setText(menu.strId);
//        }

		/**
		 * 返回键处理
		 */
		ImageButton ibBack = (ImageButton) ((Activity) context).findViewById(R.id.IMAGE_BUTTON_BACK);
		ibBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (HallActivity.getCheckedId() != R.id.radio_more) {
					return;
				}

				// / 提示是否退出软件
				PromptDialog.show(MoreHandler.context,
						((Activity) MoreHandler.context)
								.getString(R.string.STR_EXIT_APP_REQUEST),
						((DialogListener) MoreHandler.context), 0, false);
			}
		});

		/**
		 * 写微博键处理
		 */
		ImageButton ibWrite = (ImageButton) ((Activity) context).findViewById(R.id.IMAGE_BUTTON_WRITE);
		ibWrite.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (HallActivity.getCheckedId() != R.id.radio_more) {
					return;
				}
				
				Intent intent = new Intent(MoreHandler.context,
						CreativeDesignActivity.class);
				((Activity) MoreHandler.context).startActivity(intent);
			}
		});
		
		/**
		 * 设置按键事件
		 */
		RelativeLayout rlSetting = (RelativeLayout) ((Activity) context).findViewById(R.id.rlSetting);
		rlSetting.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (HallActivity.getCheckedId() != R.id.radio_more) {
					return;
				}
				
			}
		});
		
		/**
		 * 官方微博按键事件
		 */
		RelativeLayout rlOfficialWeibo = (RelativeLayout) ((Activity) context).findViewById(R.id.rlOfficialWeibo);
		rlOfficialWeibo.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (HallActivity.getCheckedId() != R.id.radio_more) {
					return;
				}
				
				Intent intent = new Intent(MoreHandler.context,
						OfficialWeiboActivity.class);
				((Activity) MoreHandler.context).startActivity(intent);
			}
		});
		
		/**
		 * 反馈意见按键事件
		 */
		RelativeLayout rlFeedback = (RelativeLayout) ((Activity) context).findViewById(R.id.rlFeedback);
		rlFeedback.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (HallActivity.getCheckedId() != R.id.radio_more) {
					return;
				}
				
				Intent intent = new Intent();

				intent.putExtra("text", ((Activity) MoreHandler.context)
						.getString(R.string.weibo_feedback));

				intent.setClass(MoreHandler.context,
						CreativeDesignActivity.class);
				((Activity) MoreHandler.context).startActivity(intent);
			}
		});
		
		/**
		 * 关于按键事件
		 */
		RelativeLayout rlAboutAdhere = (RelativeLayout) ((Activity) context).findViewById(R.id.rlAboutAdhere);
		rlAboutAdhere.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (HallActivity.getCheckedId() != R.id.radio_more) {
					return;
				}
				
				Intent intent = new Intent(MoreHandler.context,
						HelpActivity.class);
				((Activity) MoreHandler.context).startActivity(intent);
			}
		});
		
		/**
		 * 退出按键事件
		 */
		RelativeLayout rlMenuExit = (RelativeLayout) ((Activity) context).findViewById(R.id.rlMenuExit);
		rlMenuExit.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (HallActivity.getCheckedId() != R.id.radio_more) {
					return;
				}

				// / 提示是否退出软件
				PromptDialog
						.show(
								MoreHandler.context,
								((Activity) MoreHandler.context)
										.getString(R.string.STR_OFF_APP_REQUEST_BEGIN)
										+ LoginActivity.getUser().getUser()
										+ ((Activity) MoreHandler.context)
												.getString(R.string.STR_OFF_APP_REQUEST_END),
								((DialogListener) MoreHandler.context), 2,
								false);
			}
		});
	}
}
